package com.jinglvhuanjing.app.db;

import android.content.ContentValues;
import android.database.Cursor;

import androidx.annotation.NonNull;


public class DBParamTable {

    public static final String DB_TABLE_PARAM = "ljfl_table_param_info";

    public static final String DB_PARAM_ID = "id";
    public static final String DB_PARAM_PID = "pid";
    public static final String DB_PARAM_CONTENT = "content";
    public static final String DB_PARAM_EXTENDS = "extendParam";

    public static final String DROP_TABLE_PARAM = String.format("DROP TABLE IF EXISTS %s", DB_TABLE_PARAM);
    public static final String CREATE_TABLE_PARAM = String.format("CREATE TABLE IF NOT EXISTS %s " +
                    "(%s integer primary key autoincrement, %s text, %s text, %s text)",
            DB_TABLE_PARAM , DB_PARAM_ID , DB_PARAM_PID, DB_PARAM_CONTENT, DB_PARAM_EXTENDS);


    /**
     * Cursor 转 实体
     *
     * @param cursor cursor
     */
    public static DBParamBean parse(@NonNull Cursor cursor) {
        DBParamBean paramBean = new DBParamBean();
        paramBean.setId(cursor.getInt(cursor.getColumnIndex(DB_PARAM_ID)));
        paramBean.setPid(cursor.getString(cursor.getColumnIndex(DB_PARAM_PID)));
        paramBean.setContent(cursor.getString(cursor.getColumnIndex(DB_PARAM_CONTENT)));
        paramBean.setExtendsParam(cursor.getString(cursor.getColumnIndex(DB_PARAM_EXTENDS)));
        return paramBean;
    }

    /**
     * 实体 转 ContentValues
     *
     * @param dbParamBean 数据
     */
    public static ContentValues parse(@NonNull DBParamBean dbParamBean) {
        ContentValues contentValues = new ContentValues();
        contentValues.put(DB_PARAM_PID, dbParamBean.getPid());
        contentValues.put(DB_PARAM_CONTENT, dbParamBean.getContent());
        contentValues.put(DB_PARAM_EXTENDS, dbParamBean.getExtendsParam());
        return contentValues;
    }
}